<?php
class Invite extends AppModel {

    var $name = 'Invite';
    
    function saveInvite($data){
        return $this->save($data);
    }
    
    function v_fGetInviteByPharmacyId( $pharmacy_id )
    {
    	//return $this->find('all',array('conditions'=>array('Invite.pharmacy_id'=>$pharmacy_id)));
    	
    	return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Invite.vacancy_id = Vacancy.id')
                                                                              )),'fields'=>array('Invite.*,Vacancy.id, Vacancy.title'),'conditions'=>array('Invite.pharmacy_id'=>$pharmacy_id,'Vacancy.DateRange <>'=>'')));
    }
    
	function v_fGetInviteByLocumId( $Locum_id )
    {
    	//return $this->find('all',array('conditions'=>array('Invite.locum_id'=>$Locum_id)));
    	return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Invite.vacancy_id = Vacancy.id')
                                                                              )),'fields'=>array('Invite.*,Vacancy.id, Vacancy.title'),'conditions'=>array('Invite.locum_id'=>$Locum_id,'Vacancy.DateRange <>'=>'')));
    }
    
	function v_fGetInviteByStoreId( $store_id )
    {
    	return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Invite.vacancy_id = Vacancy.id')
                                                                              )),'fields'=>array('Invite.*,Vacancy.id, Vacancy.title'),'conditions'=>array('Invite.store'=>$store_id,'Vacancy.DateRange <>'=>'')));
    }
    
	function v_fGetInviteById($i_InviteId)
    {
        return $this->find('first',array('conditions'=>array('Invite.id'=>$i_InviteId)));
    }
    
	function v_fGetInviteByLocumIdAndVacancyId($i_LocumId, $i_VacancyId)
    {
        return $this->find('first',array('conditions'=>array('Invite.vacancy_id'=>$i_VacancyId, 'Invite.locum_id'=>$i_LocumId)));
    }
}
?>